<template>
	<div class="cont">
		<SearchBar v-on:search-word="searchWord"/>
		<SoundLike :results="s_results"/>
	</div>
</template>

<script>
import SearchBar from "./components/searchbar.vue"
import SoundLike from "./components/soundlike.vue"

import axios from 'axios'

export default{
	name:'WordDict',
	components:{SearchBar,SoundLike},
	data:function(){
		return {
			s_results:[]
		}
	},
	methods:{
		searchWord:function(param_01,param_02){
			let self=this;
			console.log(param_01,param_02);
			axios.get('https://api.datamuse.com/words?sl='+param_01)
			.then(function(resp){
				// console.log(resp.data)
				if(resp.data){
					if(resp.data.length>11){
						self.s_results=resp.data.splice(1,11);
						console.log(self.s_results)
					}else{
						alert('没有足够的匹配结果。')
					}
				}
			})
			.catch(function(err){
				console.log(err)
			})
			console.log('searching...')
		}
	}
}
</script>

<style>
	
</style>